/**
 * 
 */
function getDialog(){
	var foo = $('#foo');
	if(foo.length == 0) {
		var newdiv = document.createElement('div');
		document.body.appendChild(newdiv);
		foo = $(newdiv);
		foo.attr('id','foo');
		foo.css('display','none');
	}
	return foo;
}

function closeButton(){
	var newdiv = $(document.createElement('div'));
	var bb = $(document.createElement('input'));
	bb.val('OK');
	bb.attr('type','button');
	bb.click(function() {
		getDialog().dialog('destroy');
	});
	newdiv.append(bb);
	return newdiv;
}

function actionSend(u, form){
	$.ajax({
		url: u,
		data: $('#' + form).serialize(),
		type: 'POST',
		success: function(e){
			var foo = getDialog();
			foo.html('');
			foo.append(e);
			foo.append(closeButton());
			foo.dialog({modal: true});
//			$('#' + form).each(function(){
//		        this.reset();
//			});
			window.location.reload();
		},
		error: function(e){
			var foo = getDialog();
			foo.html('');
			foo.append(e.responseText);
			foo.append(closeButton());
			foo.dialog({modal: true});
		}
	});
}